package com.foreverwin.mes.lims.service.impl;


import com.foreverwin.mes.lims.service.ProducerService;
import org.apache.activemq.command.ActiveMQQueue;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jms.annotation.JmsListener;
import org.springframework.jms.core.JmsMessagingTemplate;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.jms.Destination;


@Service
@Transactional
public class ProducerServiceImpl implements ProducerService {

    @Autowired
    private JmsMessagingTemplate jmsMessagingTemplate;
    /**
     * @param queueName   queue的名称
     * @param messageBody 消息体
     * 发送消息,不需要回复
     */
    @Override
    public void sendMsgNoReponse(String queueName, String messageBody) {
        Destination destination = new ActiveMQQueue( queueName );
        jmsMessagingTemplate.convertAndSend( destination,messageBody);
    }

    /**
     * @param queueName
     * @param messageBody
     * @return String
     * 发送消息,需要回复
     */
    @Override
    public String sendMsgNeedResponse(String queueName, String messageBody) {
        String response = jmsMessagingTemplate.convertSendAndReceive( queueName,messageBody,String.class);
        return response;
    }

}
